<?php
/**
 * 获取圈子接口
 * 圈子列表、圈子详情
 * 验证用户身份token
 * @author Edwin
 */

namespace V1\Controller;

use Common\Controller\CommonController;

class CircleController extends CommonController
{
    public function rest()
    {
        switch ($this->_method) {
            case 'get': // get请求处理代码
                switch (I('get.type')) {
                    case 'get_list':
                        $this->_getList();
                        break;
                    case 'get_list_cate':
                        $this->_getCategoryList();
                        break;
                    default:
                        $this->_get();
                        break;
                }
                break;
        }
    }

    /**
     * 获取圈子详情
     */
    private function _get()
    {
        $user_id = I('get.uid');
        $data = D('Category')->get_category_list(I('get.cat_id'), null, null, null, null, $user_id);
        if (!empty($data)) {
            $this->myApiPrint(C('STATUS')['200'], 200, $data);
        } else {
            $this->myApiPrint(C('STATUS')['230'], 200, []);
        }
    }

    /**
     * 获取圈子分类
     */
    private function _getList()
    {
        $user_id = I('get.uid');
        $data = D('Category')->get_category_list(I('get.cat_id'), I('get.pid'), null, null, 1, $user_id);
        if (!empty($data)) {
            $this->myApiPrint(C('STATUS')['200'], 200, $data);
        } else {
            $this->myApiPrint(C('STATUS')['230'], 200, []);
        }
    }

    /**
     * 获取圈子无限极分类
     */
    private function _getCategoryList()
    {
        $user_id = I('get.uid');
        $data = D('Category')->get_category_list_two(I('get.cat_id'), I('get.pid'), null, null, 1, $user_id);
        if (!empty($data)) {
            $this->myApiPrint(C('STATUS')['200'], 200, $data);
        } else {
            $this->myApiPrint(C('STATUS')['230'], 200, []);
        }
    }
}
